import { getProfileAPI } from '@/api/user'
import { routes, resetRouter } from '@/router/index'

export default {
  namespaced: true,
  state: {
    profile: [],
    menuList: []
  },
  mutations: {
    setProfile(state, newProfile) {
      state.profile = newProfile
    },
    // 将过滤后的路由存在Vuex
    setMenuList(state, filterRouter) {
      state.menuList = [...routes, ...filterRouter]
    },
    // 退出清空路由
    clearMenuList(state) {
      state.menuList = [...routes]
      resetRouter()
    }
  },
  actions: {
    async getProfile(store) {
      const res = await getProfileAPI()
      store.commit('setProfile', res.data)
      return res.data.permissions
    }
  }
}
